﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HustQQModel;

namespace HustQQInterface
{
    public interface INetInterface
    {
        void SendTextToSingle(string myId,string friendId,string text);
        void SendTextToTeam(string myId,string teamId, string text);
        event SingleTextMsg RecieveTextFromSingle;
        event TeamTextMsg RecieveTextFromTeam;

        void SendPictureToSingle(string myId, string friendId, string picPath);
        void SendPictureToTeam(string myId, string teamId, string picPath);
        event SinglePicMsg RecievePicFromSingle;
        event TeamPicMsg RecievePicFromTeam;
       
        #region 文件传输
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="myId">发送方ID</param>
        /// <param name="friendId">接收方ID</param>
        /// <param name="filePath">文件路径</param>
        void SendFile(string myId, string friendId, string filePath);
        /// <summary>
        /// 确认接收文件
        /// </summary>
        /// <param name="isOk">是否接收文件</param>
        void ReplyConfirm(bool isOk);
        /// <summary>
        /// 收到文件发送请求时触发
        /// </summary>
        event FileMsg ConfirmRecieveFile;
        /// <summary>
        /// 收到接收方确认消息时触发
        /// </summary>
        event BooleanMsg ConfirmSendFile;
        /// <summary>
        /// 发送文件完毕
        /// </summary>
        event Action SendFileOver;
        /// <summary>
        /// 接收文件完毕
        /// </summary>
        event FileMsg ReceiveFileOver;
        #endregion

        #region 注册登录
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="pwd">用户在界面输入的密码</param>
        /// <returns>返回是否登录成功</returns>
        bool Login(string userId, string pwd);
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="u">当前用户信息</param>
        /// <returns>用户注册到的Id号,通过随机产生</returns>
        string Register(User u);
        bool Logout(string userId);
        #endregion

        #region 好友管理
        /// <summary>
        /// 获取用户详细信息
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="isDetail">是否需要完整信息.-完整:所以字段都必须填充,查询自己的个人信息.-不完整:不包括密码等敏感信息,查询好友的个人信息.</param>
        /// <returns>用户详细信息</returns>
        User GetUserInformation(string userId, bool isDetail);
        /// <summary>
        /// 将好友加入用户的默认分组
        /// </summary>
        /// <param name="myId">当前用户id</param>
        /// <param name="friendId">好友id</param>
        /// <param name="groupName">群组名称</param>
        /// <returns>加入好友是否成功</returns>
        bool AddFriendToUser(string myId, string friendId,string groupName);
        /// <summary>
        /// 将好友加入分组
        /// </summary>
        /// <param name="myId">当前用户id</param>
        /// <param name="friendId">好友id</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>加入分组是否成功</returns>
        bool AddFriendToGroup(string myId, string friendId, string groupName);
        /// <summary>
        /// 删除好友
        /// </summary>
        /// <param name="myId">当前用户id</param>
        /// <param name="friendId">好友id</param>
        /// <returns>是否删除成功</returns>
        bool DelFriendFromUser(string myId, string friendId);
        /// <summary>
        /// 从分组删除好友
        /// </summary>
        /// <param name="myId">当前用户id</param>
        /// <param name="friendId">好友id</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>是否删除成功</returns>
        bool DelFriendFromGroup(string myId, string friendId, string groupName);

        User GetMyself(string userId);

        User FindFriend(string userId, string findUerId);
        List<User> GetFriend(string userId);
        List<Team> GetGroup(string userId);
        #endregion

        #region 个人信息管理
        /// <summary>
        /// 修改个人信息
        /// </summary>
        /// <param name="u">当前用户详细信息</param>
        /// <returns>是否修改成功</returns>
        bool SetUserInformation(User u);
        #endregion

        #region 群组管理
        /// <summary>
        /// 新建群组
        /// </summary>
        /// <param name="myId">当前用户Id</param>
        /// <returns>用户得到的群组Id,通过随机数产生</returns>
        string NewTeamToUser(string myId);
        /// <summary>
        /// 获取群组详细信息
        /// </summary>
        /// <param name="teamId">群组Id</param>
        /// <param name="isDetail">是否需要完整信息.-完整:将Team所有字段都填充满.-不完整:不填充team中userList</param>
        /// <returns>Team的详细信息</returns>
        Team GetTeamInformation(string teamId, bool isDetail);
        /// <summary>
        /// 设置Team的详细信息
        /// </summary>
        /// <param name="t">Team的详细信息</param>
        /// <returns>是否修改成功</returns>
        bool SetTeamInformation(Team t);
        /// <summary>
        /// 将好友加入群组
        /// </summary>
        /// <param name="teamId">群组Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns>好友加入群组是否成功</returns>
        bool AddFriendToTeam(string teamId, string userId);
        /// <summary>
        /// 从群组删除好友
        /// </summary>
        /// <param name="teamId">群组Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns>删除好友是否成功</returns>
        bool DelFriendFromTeam(string teamId, string userId);

        Team FindTeam(string userId, string teamId);
        List<User> GetTeamMember(string userId, string teamId);
        #endregion

        #region 网络链路管理
        /// <summary>
        /// 设置当前登录用户的Ip和端口
        /// </summary>
        /// <param name="userId">当前用户Id</param>
        /// <param name="ipPort">端口和Ip对</param>
        /// <returns>是否设置成功</returns>
        bool SetIpPort(string userId, IpPort ipPort);
        /// <summary>
        /// 获取好友的端口Ip对
        /// </summary>
        /// <param name="userId">好友Id</param>
        /// <returns>好友的端口和Ip</returns>
        IpPort GetIpPort(string userId);
        #endregion
        
    }
    public delegate void SingleTextMsg(string userId,string text,DateTime time);
    public delegate void TeamTextMsg(string userId, string teamId, string text, DateTime time);
    public delegate void SinglePicMsg(string userId, string picPath, DateTime time);
    public delegate void TeamPicMsg(string userId, string teamId, string picPath, DateTime time);
    public class AddFriendResult
    {
        public bool accept;
        public string message;
        public string group;
        public string note = "";
    }
    public delegate AddFriendResult AddFriendMsg(string userId, string message);
    public delegate void AddFriendReply(string userId, bool accept, string message, string group);
    public class AddTeamResult
    {
        public bool accept;
        public string message;
    }
    public delegate AddTeamResult AddTeamMsg(string userId, string teamId, string message);
    public delegate void AddTeamReply(string teamId, bool accept, string message);
    /// <summary>
    /// 文件信息
    /// </summary>
    /// <param name="userId">发送者ID</param>
    /// <param name="fileInfo">文件详细信息</param>
    /// <param name="time">发送时间</param>
    public delegate void FileMsg(string userId, FileInformation fileInfo, DateTime time);
    public delegate void BooleanMsg(bool isOk);
}
